package test;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;


public class testExport {

	@SuppressWarnings("deprecation")
public void test(){
		String url = "你好.xls";
		// TODO Auto-generated method stub
		//创建一个webbook，对应一个excel文件
		HSSFWorkbook wb = new HSSFWorkbook();
			//在webbook中添加一个sheet,对应excel文件中的sheet
			HSSFSheet sheet= wb.createSheet("成绩表");
			//在sheet中添加表头第0行，注意老版本poi对excel的行数猎术有限制short
			HSSFRow row = sheet.createRow(0);
			//创建单元格，并设置表头居中
			HSSFCellStyle style = wb.createCellStyle();
			style.setAlignment(HSSFCellStyle.ALIGN_CENTER);//创建一个居中各式
			
			HSSFCell cell = row.createCell((short)0);
			cell.setCellValue("学号");
			cell.setCellStyle(style);
			cell = row.createCell((short)1);
			cell.setCellValue("姓名");
			cell.setCellStyle(style);
			cell = row.createCell((short)2);
			cell.setCellValue("课程名称");
			cell.setCellStyle(style);
			cell = row.createCell((short)3);
			cell.setCellValue("学年");
			cell.setCellStyle(style);
			cell = row.createCell((short)4);
			cell.setCellValue("学期");
			cell.setCellStyle(style);
			cell = row.createCell((short)5);
			cell.setCellValue("选课课号");
			cell.setCellStyle(style);
			cell = row.createCell((short)6);
			cell.setCellValue("成绩");
			cell.setCellStyle(style);
			row = sheet.createRow((int) 0+ 1); 
					//创建单元格，并设值
					row.createCell((short)0).setCellValue("df");
					row.createCell((short)1).setCellValue("dsf");
					row.createCell((short)2).setCellValue("geui");
					row.createCell((short)3).setCellValue("qu");
					row.createCell((short)4).setCellValue("sf");
					row.createCell((short)5).setCellValue("kl");
					row.createCell((short)6).setCellValue("ere");
			
			try {
				String url1=new String(url.getBytes("UTF-8"),"GBK");
				FileOutputStream fout = new FileOutputStream("/usr/" + url1) ;
				wb.write(fout);
				fout.close();
			} catch (FileNotFoundException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			

	}

}
